Skip to content

Optional $skipWhenEmpty parameter for #[DataProvider] and #[DataProviderExternal]#6565

Closed
sebastianbergmann wants to merge 1 commit intomainfrom
issue-6404/data-provider-opt-in-empty-data-set
Closed

Optional $skipWhenEmpty parameter for #[DataProvider] and #[DataProviderExternal]#6565
sebastianbergmann wants to merge 1 commit intomainfrom
issue-6404/data-provider-opt-in-empty-data-set

Conversation

@sebastianbergmann
Copy link
Copy Markdown
Owner

@sebastianbergmann sebastianbergmann commented Apr 5, 2026

This implements an optional $skipWhenEmpty parameter (defaulting to false) for the #[DataProvider] and #[DataProviderExternal] attributes. When set to true, a data provider that returns an empty iterable will cause the test to be skipped instead of triggering an error.

Usage:

#[DataProvider('provider', skipWhenEmpty: true)]
public function testSomething(string $value): void
{
    // ...
}

Note: Parameter names are not covered by the backward compatibility promise for PHPUnit.

When all data providers for a test method return no data and at least one of them has skipWhenEmpty: true, the test is created as a single test case that skips itself with the message "The data provider for this test provided no data, which is explicitly permitted". The default behavior (error on empty data provider) is unchanged.

Closes #6404.

@sebastianbergmann
Copy link
Copy Markdown
Owner Author

@stof Is this what you had in mind?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.91%. Comparing base (043a636) to head (5fe6f25).
⚠️ Report is 111 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6565   +/-   ##
=========================================
  Coverage     96.90%   96.91%           
- Complexity     7604     7613    +9     
=========================================
  Files           819      819           
  Lines         23512    23533   +21     
=========================================
+ Hits          22785    22806   +21     
  Misses          727      727           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stof
Copy link
Copy Markdown
Contributor

stof commented Apr 7, 2026

@sebastianbergmann yes, exactly.

@sebastianbergmann sebastianbergmann marked this pull request as ready for review April 7, 2026 08:38
@sebastianbergmann sebastianbergmann added this to the PHPUnit 13.2 milestone Apr 13, 2026
@sebastianbergmann sebastianbergmann self-assigned this Apr 13, 2026
@sebastianbergmann sebastianbergmann deleted the issue-6404/data-provider-opt-in-empty-data-set branch April 13, 2026 07:30
sebastianbergmann added a commit to sebastianbergmann/phpunit-documentation-english that referenced this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/data-provider Data Providers feature/metadata/attributes type/enhancement A new idea that should be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add (opt-in?) support for data providers returning an empty iterable

2 participants